package routes

import (
	"embed"
	"html/template"
	"io/fs"
	"net/http"
	"zpay/app/http/middlewares"

	"github.com/gin-gonic/gin"
)

func RegisterWebRoutes(r *gin.Engine, staticFS embed.FS) {

	// 设置 html 模板
	r.SetHTMLTemplate(template.Must(template.New("").ParseFS(staticFS, "web/dist/*.html")))

	// 限流
	zr := r.Group("/zpay")
	zr.Use(middlewares.LimitIP("1000-H"))

	// 静态文件
	assets, _ := fs.Sub(staticFS, "web/dist/assets")
	zr.StaticFS("/assets", http.FS(assets))

	// 返回 index.html
	zr.GET("/", func(c *gin.Context) {
		c.HTML(http.StatusOK, "index.html", gin.H{})
	})
}
